<?php

namespace app\index\service;

use app\index\model\UM as UM;

/**
 * Class PromotionCallbackService
 * @package app\index\service
 */
class PromotionCallbackService
{
    /**
     *
     * @param UM $user
     * @param array $params
     * @return void
     */
    public function add(array $params): void
    {
        $promotionActionId = $params['promotionActionId'] ?? null;
        $params['clickid'] ??= '';
        $params['logidUrl'] ??= '';

        if (!is_id($promotionActionId)) {
            return;
        }

        // 渠道链路
        ['pf' => $pf, 'chain' => $chain, 'promotionGroupId' => $promotionGroupId] = getChainParams();

        $this->getPromotionCallbackService()->pushEventsByActionId($promotionActionId, $promotionGroupId, $chain, $pf, $params);
    }

    private function getPromotionCallbackService(): \app\common\service\PromotionCallbackService
    {
        return app(\app\common\service\PromotionCallbackService::class);
    }
}
